package com.bdqn.hospital.mapper;

import com.bdqn.hospital.pojo.Schedule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @version : 1.0
 * @Author :guogd
 * @createTime: 2023/03/01 14:29
 * @Description: com.bdqn.hospital.mapper
 */
@Mapper
public interface ScheduleMapper {
    /**
     * 问诊结束后修改医生排期表的问诊时间和诊断病人数量
     * @param id
     * @return
     */
    @Update("update `schedule` set quantity = quantity+1,remaining_quantity = remaining_quantity-1,inquiry_time = now() where id =#{id}")
    Integer updCountAndTime(@Param("id") Integer id);


    /**
     * 根据就诊科室和时间段获取信息
     * @param departmentId
     * @param sign
     * @return
     */
    List<Schedule> getByDepartmentIdAndSign(Integer departmentId, Integer sign);

    /**
     * 根据用户id获取医生排期表
     * @param userId
     * @return
     */
    @Select("select * from schedule where user_id=#{userId}")
    Schedule getByUserId(Integer userId);

    /**
     * 添加病人剩余数量
     * @return
     */
    @Update("update schedule set remaining_quantity=remaining_quantity+1")
    Integer addRemainingQuantity();
}
